Stockname = char(Stockname);
Indexname = char(Indexname);
[Stock Index Date PriceStock PriceIndex] = getStock_Index(Stockname,Indexname);
%Get the return of stock and index
rStock = PriceStock(2:end)./PriceStock(1:end-1) - 1;
rIndex = PriceIndex(2:end)./PriceIndex(1:end-1) - 1;
%-----------------------------------------------------------
%Estimation Robust Trim 1Year
%-----------------------------------------------------------
%Rolling window
rolling = 260;
[n,m] = size(rStock);
k = n-rolling;
datan = x2mdate(Date,0);
datam=datan(262:end);

percent = 1

for i = 1:k
    j = i+260;
    rStockRobust = rStock(i:j,1);
    rIndexRobust = rIndex(i:j,:);
    
    %setting the values smaller than the alpha quantile to that of the alpha quantile 
    rIndexRobust(find(rIndexRobust <= (prctile(rIndexRobust, (percent / 2)))))=(prctile(rIndexRobust, (percent / 2)));
    rStockRobust(find(rStockRobust <= (prctile(rStockRobust, (percent / 2)))))=(prctile(rStockRobust, (percent / 2)));
    %setting the 1?alpha quantile to those of that of the alpha quantile 
    rIndexRobust(find(rIndexRobust >= (prctile(rIndexRobust, (100-percent/2)))))=(prctile(rIndexRobust, (100-percent/2)));
    rStockRobust(find(rStockRobust >= (prctile(rStockRobust, (100-percent/2)))))=(prctile(rStockRobust, (100-percent/2)));

    betaRobust = robustfit(rIndexRobust,rStockRobust,'ols');
    betaRobust_Graph(i,:) = betaRobust;
end
%Output to Excel
ExcelRobust=[datam,betaRobust_Graph(:,2)];